package LeetCode.month04.day94;

/**
 * @author 16778
 * @date 2025/11/3 8:30
 * @description
 */
public class No1578 {
    static void main() {
        minCost("aaa" +
                        "bbb" +
                        "a" +
                        "bbbb",
                new int[]{3,5,10,
                        7,5,3,
                        5,
                        5,4,8,1});
    }
    public static int minCost(String colors, int[] neededTime) {
        char[] arr = colors.toCharArray();
        int res = 0;
        int left = 0;
        int right;
        int sum = neededTime[0];
        int max = neededTime[0];
        for (right = 1; right < arr.length; right++) {
            if(arr[right]==arr[right-1]) {
                max = Math.max(max, neededTime[right]);
                sum+=neededTime[right];
            }else{
                left = right;
                res+=sum-max;
                sum=neededTime[right];
                max=neededTime[right];
            }
        }
        if(left!=right){
            res+=sum-max;
        }
        return res;
    }
}
